package com.somiz.article;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;

import com.somiz.main.Control;
import com.somiz.objet.ObjetIdentifiableDaoImpl;

public class ArticleDaoImpl extends ObjetIdentifiableDaoImpl<Article> implements
		ArticleDao {
	public Boolean isExisteAvecCode(Article article, Session session) {
		Boolean isExiste = false;
		Article articleTest = new Article();
		List<Article> articles = Control.getArticleDao().charger(articleTest,
				session);
		for (int i = 0; i < articles.size(); i++) {
			if (article.getCode().equals(articles.get(i).getCode())) {
				isExiste = true;
			}
		}
		return isExiste;
	}

	public Article TrouverAvecCode(Article article, Session session) {
		Article articleTest = new Article();
		List<Article> articles = Control.getArticleDao().charger(articleTest,
				session);
		for (int i = 0; i < articles.size(); i++) {
			if (article.getCode().equals(articles.get(i).getCode())) {
				article = articles.get(i);

			}
		}
		return article;
	}

	public List<String> ListeCodesArticle(Session session) {
		Article articleTest = new Article();
		List<Article> articles = Control.getArticleDao().charger(articleTest,
				session);
		List<String> CodesArticle = new ArrayList<>(0);
		CodesArticle.add("");
		for (int i = 0; i < articles.size(); i++) {
			CodesArticle.add(articles.get(i).getCode());
		}
		return CodesArticle;
	}
}
